﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.ServiceProcess;
using System.Text;

namespace SpiderService
{
    partial class SpiderService : ServiceBase
    {
        private Int32 times;
        private int heartbeat = Convert.ToInt16(System.Configuration.ConfigurationManager.AppSettings["Heartbeat"]);
        public SpiderService()
        {
            InitializeComponent();
        }
        protected override void OnStart(string[] args)
        {
            times = 0;
            this.timer1.Enabled = true;
          //  BLL.Message.MyLog4Net.Write("timer", "webcheck start");
        }

        protected override void OnStop()
        {
            timer1.Enabled = false;
        }

        private void timer1_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
        {
            //按心跳输出周期输出周期
            if (heartbeat > 0 && times % heartbeat == 0)
            {
                //BLL.Message.MyLog4Net.Write("timer", "System Heartbeat");
                times = 0;
            }
            times++;

            try
            {
                //BLL.Message.MessageFactor.SendMessage("1起点");
                timer1.Enabled = false;
                BLL.CheckMain main = new BLL.AutoCheckMain();
                main.xMain();
                
            }
            catch (Exception ex)
            {
                BLL.Message.MyLog4Net.Write(ex.Message+ex.StackTrace, "timer");
            }
            this.timer1.Enabled = true;
           // BLL.Message.MessageFactor.SendMessage("2终点");
        }
    }
}
